package ar.com.spsolutions.splibrary.utils;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import ar.com.spsolutions.splibrary.entity.Entity;

public class GenericTestRepository extends HibernateDaoSupport {

	public void save(final Entity entity) {
		this.getHibernateTemplate().save(entity);
		this.getHibernateTemplate().flush();
	}

	public void delete(final Entity entity) {
		this.getHibernateTemplate().delete(entity);
	}

	public <T> T update(final T entity) {
		this.getHibernateTemplate().update(entity);
		return entity;
	}

	public <T> T findById(final Serializable id, final Class<T> persistentClass) {
		return this.getHibernateTemplate().get(persistentClass, id);
	}

	@SuppressWarnings("unchecked")
	public <T> List<T> findAll(final Class<T> persistentClass) {
		return this.getHibernateTemplate().find(
				"from " + persistentClass.getName() + " o");

	}
}
